//https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/
package codeRandomThoughts.Test452用最少数量的箭引爆气球;

import java.util.Arrays;

public class Solution2 {
    public int findMinArrowShots(int[][] points) {
        //根据气球的左侧坐标从小到大排序
        Arrays.sort(points, (p1, p2) -> Integer.compare(p1[0], p2[0]));

        int count = 1;//至少需要一根箭
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] > points[i - 1][1]) {//当前气球与前面气球不挨
                count++;
            } else {
                //更新重叠边界
                points[i][1] = Math.min(points[i][1], points[i - 1][1]);
            }
        }

        return count;
    }
}
